import Vue from 'vue'
import axios from 'axios'
import allApi from './allApi'

// 设置axios请求的token
// axios.defaults.headers.common['token'] = 'f4c902c9ae5a2a9d8f84868ad064e706'
//设置请求头
// axios.defaults.headers.post["Content-type"] = "application/json"

// let basePath = process.env.NODE_ENV === 'development' ? '/mvc' : '/';
let basePath = '/';

let xhr = axios.create({
  baseURL: basePath,
  timeout: 5000
})
let Axios = {
  get(url, params) {
    return new Promise((resolve, reject) => {
      xhr.get(url, params).then(res => {
        resolve(res.data)
      }).catch(err => {
        reject(err)
      })
    })
  },
  post(url, data) {
    return new Promise((resolve, reject) => {
      xhr.post(url, data, {
        headers: {
          "Content-Type": "application/json",
        }
      }).then(res => {
        resolve(res.data)
      }).catch(err => {
        reject(err)
      })
    })
  }
}
export default Axios
